package com.haoan.index.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.haoan.common.annotation.Anonymous;
import com.haoan.index.domain.Personnel;
import com.haoan.index.service.PersonnelService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haoan.common.annotation.Log;
import com.haoan.common.core.controller.BaseController;
import com.haoan.common.core.domain.AjaxResult;
import com.haoan.common.enums.BusinessType;
import com.haoan.index.domain.Introduce;
import com.haoan.index.service.IntroduceService;
import com.haoan.common.utils.poi.ExcelUtil;
import com.haoan.common.core.page.TableDataInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 企业文化Controller
 *
 * @author autoGen
 * @date 2025-01-03
 */
@Api(value="企业文化",tags = "企业文化")
@RestController
@RequestMapping("/index/introduce")
public class IntroduceController extends BaseController
{
    @Resource
    private IntroduceService introduceService;
    @Resource
    private PersonnelService personnelService;

    /**
     * 查询企业文化列表
     */
    @ApiOperation("查询企业文化列表")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Introduce introduce)
    {
        startPage();
        List<Introduce> list = introduceService.selectIntroduceList(introduce);
        return getDataTable(list);
    }

    /**
     * 导出企业文化列表
     */
    @ApiOperation("导出企业文化列表")
    @PreAuthorize("@ss.hasPermi('index:introduce:export')")
    @Log(title = "企业文化", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Introduce introduce)
    {
        List<Introduce> list = introduceService.selectIntroduceList(introduce);
        ExcelUtil<Introduce> util = new ExcelUtil<Introduce>(Introduce.class);
        util.exportExcel(response, list, "企业文化数据");
    }

    /**
     * 获取企业文化详细信息
     */
    @ApiOperation("获取企业文化详细信息")
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        Introduce introduce = introduceService.selectIntroduceById(id);
        LambdaQueryWrapper<Personnel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Personnel::getIntroduceId,id);
        List<Personnel> personnelList = personnelService.list(queryWrapper);
        introduce.setPersonnelList(personnelList);
        return success(introduce);
    }

    /**
     * 新增企业文化
     */
    @ApiOperation("新增企业文化")
    @PreAuthorize("@ss.hasPermi('index:introduce:add')")
    @Log(title = "企业文化", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Introduce introduce)
    {
        return toAjax(introduceService.insertIntroduce(introduce));
    }

    /**
     * 修改企业文化
     */
    @ApiOperation("修改企业文化")
    @PreAuthorize("@ss.hasPermi('index:introduce:edit')")
    @Log(title = "企业文化", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Introduce introduce)
    {
        return toAjax(introduceService.updateIntroduce(introduce));
    }

    /**
     * 删除企业文化
     */
    @ApiOperation("删除企业文化")
    @PreAuthorize("@ss.hasPermi('index:introduce:remove')")
    @Log(title = "企业文化", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(introduceService.deleteIntroduceByIds(ids));
    }
}
